package com.d6game.purchase.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.net.Uri;

public class PurchaseUtil {
	
	public static boolean isDigits(String string){
		for (int i = 0; i < string.length(); i++) {
			if (!Character.isDigit(string.charAt(i))) {
				return false;
			}
		}
		return true;
	}
	public static String saveImg(Bitmap bitmap, String dirPath, String fileName){
		String filePath = "";  
        if (bitmap == null) {  
            return filePath;  
        } else {  
        	File dirName = new File(dirPath);
        	if (!dirName.isDirectory()){
        		dirName.mkdirs();
        	} 
            filePath=dirPath+ fileName;
            File destFile = new File(filePath);  
            OutputStream os = null;  
            try {  
                os = new FileOutputStream(destFile);  
                bitmap.compress(CompressFormat.JPEG, 100, os);  
                os.flush();  
                os.close();  
            } catch (IOException e) {  
                filePath = "";  
            }  
        }  
        return filePath;  
	}

	public static Bitmap getBitmapByPath(String path) {
		  if (path == null){
			  return null;
		  }
		  Bitmap temp = null;
		  try {
		    temp = BitmapFactory.decodeFile(path);
		  } catch (Exception e) {
		    e.printStackTrace();
		  } catch (Error e) {
		    e.printStackTrace();
		  }
		  return temp;
		 }
	public static Uri getUriFromPath(String filename){
		File file = new File(filename);
		try {
			Uri uri = Uri.fromFile(file);
			return uri;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
